package com.newgoldcurrency.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.newgoldcurrency.R;
import com.newgoldcurrency.bean.NoticeBean;
import com.newgoldcurrency.databinding.ItemNoticeBinding;

import java.util.List;

public class NoticeAdapter extends ArrayAdapter<NoticeBean> {
    private final Activity context;
    public NoticeAdapter(@NonNull Activity context, @NonNull List<NoticeBean> objects) {
        super(context, 0, objects);
        this.context=context;
    }
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        @SuppressLint("ViewHolder") @NonNull ItemNoticeBinding binding = ItemNoticeBinding.inflate(context.getLayoutInflater());
        NoticeBean bean = getItem(position);
        binding.itemNoticeTitle.setText(bean.title);
        binding.itemNoticeTime.setText(bean.time);
        RequestOptions options = new RequestOptions().transform(new MultiTransformation<>(new CenterCrop(),new RoundedCorners(15)));
//        Glide.with(context).load(R.drawable.test_cat).error(R.color.white).placeholder(R.color.white).apply(options).into(binding.itemNoticeIv);
        Glide.with(context).load(bean.image).error(R.color.white).placeholder(R.color.white).apply(options).into(binding.itemNoticeIv);
        return binding.getRoot();
    }
}